<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
 * 通过新浪接口通过ip获得具体地址
 */
function get_address_by_ip($ip)
{
    $loc = "";
    $url = 'http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_ENCODING, 'utf8');
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取数据返回
    $location = curl_exec($ch);
    $location = json_decode($location, true);
    // print_r($location);
    curl_close($ch);
    if ($location['code'] == 0) {
        return $location['data']['city'];
    } else {
        return false;
    }
    // return $loc;
}
